home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / music / midispec.lzh / MIDISPEC.DOC
Text File  |  1988-01-25  |  29KB  |  637 lines

  1. The official MIDI 1.0 specification is available from:
  2. IMA
  3. the International MIDI Association
  4. 11857 Hartsook St.
  5. North Holllywoood, CA  91607
  6. (818) 505-8964
  7.  
  8. The complete MIDI spec as developed by the Japanese manufacturers
  9. and adopted by the "World" at the Summer '85 NAMM show
  10. is available to IMA members ($40/yr) foor $30 non-members $35.
  11.  
  12. The sketchy hardware and byte definitions are free with membership.
  13.  
  14. The following is an expanded MIDI definition (sort of in-between
  15. IMA MIDI 1.0 and the new $35 booklet) entered into the public
  16. domain on USENET net.musi.synth by an altruistic musically 
  17. inclined engineer:
  18.  
  19. Bob McQueer
  20. 22 Bcy, 3151
  21.  
  22. All rites reversed.  Reprint what you like.
  23.  
  24.  
  25.                        The USENET MIDI Primer
  26.                             Bob McQueer
  27.  
  28. PURPOSE
  29.  
  30. It seems as though many people in the USENET community have an interest
  31. in the Musical Instrument Digital Interface (MIDI), but for one reason
  32. or another have only obtained word of mouth or fragmentary descriptions
  33. of the specification.  Basic questions such as "what's the baud rate?",
  34. "is it EIA?" and the like seem to keep surfacing in about half a dozen
  35. newsgroups.  This article is an attempt to provide the basic data to
  36. the readers of the net.
  37.  
  38. REFERENCE
  39.  
  40. The major written reference for this article is version 1.0 of the MIDI
  41. specification, published by the International MIDI Association, copyright
  42. 1983.  There exists an expanded document.  This document, which I have not
  43. seen, is simply an expansion of the 1.0 spec. to contain more explanatory
  44. material, and fill in some areas of hazy explanation.  There are no
  45. radical departures from 1.0 in it.  I have also heard of a "2.0" spec.,
  46. but the IMA claims no such animal exists.  In any event, backwards
  47. compatibility with the information I am presenting here should be
  48. maintained.
  49.  
  50. CONVENTIONS
  51.  
  52. I will give constants in C syntax, ie. 0x for hexadecimal.  If I
  53. refer to bits by number, I number them starting with 0 for the low
  54. order (1's place) bit.  The following notation:
  55.  
  56. >>
  57.  
  58. text
  59.  
  60. <<
  61.  
  62. will be used to delimit commentary which is not part of the "bare-
  63. bones" specification.  A sentence or paragraph marked with a question
  64. mark in column 1 is a point I would kind of like to hear something
  65. about myself.
  66.  
  67. OK, let's give it a shot.
  68.  
  69. PHYSICAL CONNECTOR SPECIFICATION
  70.  
  71. The standard connectors used for MIDI are 5 pin DIN.  Separate sockets
  72. are used for input and output, clearly marked on a given device.  The
  73. spec. gives 50 feet as the maximum cable length.  Cables are to be
  74. shielded twisted pair, with the shield connecting pin 2 at both ends.
  75. The pair is pins 4 and 5, pins 1 and 3 being unconnected:
  76.  
  77.                               2
  78.                           5       4
  79.                         3           1
  80.  
  81.  
  82. A device may also be equipped with a "MIDI-THRU" socket which is used
  83. to pass the input of one device directly to output.
  84.  
  85. >>
  86.         I think this arrangement shows some of the original conception
  87.         of MIDI more as a way of allowing keyboardists to control
  88.         multiple boxes than an instrument to computer interface.  The
  89.         "daisy-chain" arrangement probably has advantages for a performing
  90.         musician who wants to play "stacked" synthesizers for a desired
  91.         sound, and has to be able to set things up on the road.
  92. <<
  93.  
  94. ELECTRICAL SPECIFICATION
  95.  
  96. Asynchronous serial interface.  The baud rate is 31.25 Kbaud (+/- 1%).
  97. There are 8 data bits, with 1 start bit and 1 stop bit, for 320 microseconds
  98. per serial byte.
  99.  
  100. MIDI is current loop, 5 mA.  Logic 0 is current ON.  The specification
  101. states that input is to be opto-isolated, and points out that Sharp
  102. PC-900 and HP 6N138 optoisolators are satisfactory devices.  Rise and
  103. fall time for the optoisolator should be less than 2 microseconds.
  104.  
  105. The specification shows a little circuit diagram for the connections
  106. to a UART.  I am not going to reproduce it here.  There's not much
  107. to it - I think the important thing it shows is +5 volt connection
  108. to pi 4 of the MIDI out with pin 5 going to the UART, through 220
  109. ohm load resisors. It also shows that you're supposed to connect
  110. to the "in" side of the UART through an optoisolator, and to the
  111. MIDI-THRU on the UART side of the isolator.
  112.  
  113.         
  114. >>
  115.         I'm not much of a hardware person, and don't really know what
  116.         I'm talking about in paragraphs like the three above.  I DO
  117.         recognize that this is a "non-standard" specification, which
  118.         won't work over serial ports intended for anything else.  People
  119.         who do know about such things seem to either have giggling
  120.         or gagging fits when they see it, depending on their dispos-
  121.         itions, saying things like "I haven't seen current loop since
  122.         the days of the old teletypes".  I also know the fast 31.25
  123.         Kbaud pushes the edge for clocking commonly available UART's.
  124. <<
  125.  
  126. DATA FORMAT
  127.  
  128. For standard MIDI messages, there is a clear concept that one device
  129. is a "transmitter" or "master", and the other a "receiver" or "slave".
  130. Messages take the form of opcode bytes, followed by data bytes.
  131. Opcode bytes are commonly called "status" bytes, so we shall use
  132. this term.
  133.  
  134. >>
  135.         very similar to handling a terminal via escape sequences.  There
  136.         aren't ACK's or other handshaking mechanisms in the protocol.
  137.  
  138. <<
  139.  
  140. Status bytes are marked by bit 7 being 1.  All data bytes must
  141. contain a 0 in bit 7, and thus lie in the range 0 - 127.
  142.  
  143. MIDI has a logical channel concept.  There are 16 logical channels,
  144. encoded into bits 0 - 3 of the status bytes of messages for
  145. which a channel number is significant.  Since bit 7 is taken over
  146. for marking the status byte, this leaves 3 opcode bits for message
  147. types with a logical channel.  7 of the possible 8 opcodes are
  148. used in this fashion,  reserving the status bytes containing all
  149. 1's in the high nibble for "system" messages which don't have a
  150. channel number.  The low order nibble in these remaining messages
  151. is  eelly ffuther  pcodee
  152.  
  153. >>
  154.         II you are  nterested in rrceiving MIDI input, look over the
  155.         SYSTEM messages even if you wish to ignore them.  Especially the
  156.         "system exclusive" and "real time" messages.  The real time
  157.         messages may be legally inserted in the middle of other data,
  158.         and you should be aware of them, even though many devices won't
  159.         use them.
  160. <<
  161.  
  162. VOICE MESSAGES
  163.  
  164. I will cover the message with channel numbers first.  The opcode determines
  165. the number of data bytes for a single message (see "running status byte",
  166. below).  The specification divides these into "voice" and "mode" messages.
  167. The "mode" messages are for control of the logical channels, and the control
  168. opcodes are piggybacked onto the data bytes for the "parameter" message.  I
  169. will go into this after describing the "voice messages".  These messages are:
  170.  
  171. status byte   meaning        data bytes
  172.  
  173. 0x80-0x8f     note off       2 - 1 byte pitch, followed by 1 byte velocity
  174. 0x90-0x9f     note on        2 - 1 byte pitch, followed by 1 byte velocity
  175. 0xa0-0xaf     key pressure   2 - 1 byte pitch, 1 byte pressure (after-touch)
  176. 0xb0-0xbf     parameter      2 - 1 byte parameter number, 1 byte setting
  177. 0xc0-0xcf     program        1 byte program selected
  178. 0xd0-0xdf     chan. pressure 1 byte channel pressure (after-touch)
  179. 0xe0-0xef     pitch wheel    2 bytes giving a 14 bit value, least
  180.                                    significant 7 bits first
  181.  
  182. Many explanations are necessary here:
  183.  
  184. For all of these messages, a convention called the "running status
  185. byte" may be used.  If the transmitter wishes to send another message
  186. of the same type on the same channel, thus the same status byte, the
  187. status byte need not be resent.
  188.  
  189. Also, a "note on" message with a velocity of zero is to be synonymous
  190. with a "note off".  Combined with the previous feature, this is intended
  191. to allow long strings of notes to be sent without repeating status bytes.
  192.  
  193.  
  194. >>
  195.         From what I've seen, the "zero velocity note on" feature is very
  196.         h